import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-03-22
 * Time: 17:09
 */
public class Demo1 {
    //不规则二维数组
    public static void main(String[] args) {
        int [][] arr = new int [2][0];
        arr[0] = new int[2];
        arr[1] = new int [4];
        System.out.println(Arrays.deepToString(arr));
    }
    //二维数组
    public static void main4(String[] args) {
        int[][] arr = new int[2][3];
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                arr[i][j] = 10;
            }
        }
        //第一种 双重for循环打印
        //第二种打印方式
        for (int[] ret : arr) {
            for (int x:ret) {
                System.out.print(x+" ");
            }
            System.out.println();
        }
        //第三种打印方式
        System.out.println(Arrays.deepToString(arr));
    }
    //冒泡排序
    public static void main3(String[] args) {
        int []arr = {7,88,1,3,5,4,2,48,88,5};
        for (int i = 0; i < arr.length - 1; i++) {
            boolean flag = false;
            for (int j = 0; j < arr.length - i - 1; j++) {
                if( arr[j] > arr[j+1]) {
                    int temp = 0;
                    temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] =temp;
                    flag = true;
                }
            }
            if( flag == true) {
                break;
            }
        }
        System.out.println(Arrays.toString(arr));
    }
    //库函数的使用
    public static void main2(String[] args) {
       int [] arr1 = {1,2,3,4,56,7,8};
       int [] arr2 = {1,2,3,4,56,7,8};
        //Arrays.equals 使用
        boolean ret = Arrays.equals(arr1,arr2);
        System.out.println(ret);
        //fill 填充的使用
        Arrays.fill( arr1,0,arr1.length,10);
        System.out.println(Arrays.toString(arr1));
    }
    public static void main1(String[] args) {
        int []arr = {6,10,11,4,5,17,7,8};
        Arrays.sort(arr);
        System.out.println("排序后的数组");
        System.out.println(Arrays.toString(arr));//Arrays.sort默认是升序
        int index = Arrays.binarySearch(arr,30);//使用库函数的二分查找
        System.out.println(index);
        //search(arr,1);
    }
    //二分查找
    public static void search( int[] arr,int key) {
        int left = 0;
        int right = arr.length-1;
        while(left <= right) {
            int mid = (left + right) / 2;
            if( arr[mid] < key) {
                left = mid +1;
            } else if(arr[mid] > key) {
                right = mid - 1;
            } else {
                System.out.println("找到了，下标是"+mid);
                return ;
            }
        }
        System.out.println("没找到");

    }
}
